import { ifs, ts, Tsrv } from '@/services';
import { N_cFlowchart, tvs } from '@/types';

class T_cmd {
  // 主组件箱
  private compBox: ifs.I_compBox;

  // 主组件ID
  private compID: string;

  private compName: string; // 主组件名称

  // 主组件实例
  private self: any;

  private graph: N_cFlowchart.x6Graph;

  public regGraphEvents: Map<
    N_cFlowchart.EVENTS,
    (e: N_cFlowchart.I_eventParams) => void
  > = new Map();

  // 内部联络单明细 节点数据
  private nodesData: Array<any>;

  // 主组件created里初始化
  public init(self: any, compBoxInfo: ifs.I_compBoxInfo) {
    this.self = self;
    this.compBox = compBoxInfo.TcompBox;
    this.compID = compBoxInfo.compID;
    this.compName = self.G_compName;

    // 注册节点 点击事件
    this.regGraphEvents.set(
      N_cFlowchart.EVENTS.NODE_CLICK,
      this.graphNodeClick
    );
  }

  public setGraph(graph: N_cFlowchart.x6Graph) {
    this.graph = graph;
  }

  graphNodeClick = (e: N_cFlowchart.I_eventParams) => {
    const node = e.node;
    const nodeProp = node.getProp();
    const data = nodeProp.data;
    // if (nodeProp.shape === 'bpmn-begin' || nodeProp.shape === 'bpmn-end') {
    //   //
    // } else {
    //   this.self.setSelectedNode(e.cell.id);
    // }
    this.self.setSelectedNode(e.cell.id);
  };

  public setNodesData(nodesData: Array<any>) {
    this.nodesData = nodesData;
  }

  /**
   * @description: 获取内部联络单明细数据
   * @description: （1、获取所有审批节点数据，2、找到当前审批人）
   * @return {*}
   * @author: swc
   * @Date: 2024-11-21 10:29:33
   * @LastEditors: swc
   * @LastEditTime: Do not edit
   */
  public getLiaisonDet(liaisonID: string): Promise<any> {
    const that = this.self;
    const dbType = Tsrv.globalVar.dbType.MYSQL;
    const tableName = Tsrv.globalVar.tableName.SYS_INTERNAL_LIAISON_SHEET_DET;
    const gpd = new ts.T_getPartDataArg();
    gpd.setFunName(tableName).setLang(that.$i18n.locale || 'en-US');
    gpd.setPage(1, 99999).setDbType(dbType);
    gpd.setFilter({
      master_bill_id: { $in: [liaisonID] }
    });
    return Tsrv.getData<any, ifs.I_getPartDataArg>(gpd);
  }

  /**
   * @description: 获取内部联络单 操作历史数据
   * @return {*}
   * @author: swc
   * @Date: 2024-11-21 10:29:33
   * @LastEditors: swc
   * @LastEditTime: Do not edit
   */
  public getLiaisonLog(liaisonID: string): Promise<any> {
    const that = this.self;
    const dbType = Tsrv.globalVar.dbType.MYSQL;
    const tableName = Tsrv.globalVar.tableName.SYS_INTERNAL_LIAISON_SHEET_LOG;
    const gpd = new ts.T_getPartDataArg();
    gpd.setFunName(tableName).setLang(that.$i18n.locale || 'en-US');
    gpd.setPage(1, 99999).setDbType(dbType);
    gpd.setSort([
      new ts.T_sort()
        .setField('create_time')
        .setValue(tvs.V_sortValue.DESC)
        .setWeight(1)
    ]);
    gpd.setFilter({
      master_bill_id: { $in: [liaisonID] }
    });
    return Tsrv.getData<any, ifs.I_getPartDataArg>(gpd);
  }

  /**
   * @description: 根据流程图id 获取流程图数据、
   * @param {*} id 流程图id
   * @return {*}
   * @author: swc
   * @Date: 2024-11-21 10:11:18
   * @LastEditors: swc
   * @LastEditTime: Do not edit
   */
  public getBpmnData(id: string): Promise<any> {
    const that = this.self;
    const dbType = Tsrv.globalVar.dbType.MYSQL;
    const tableName = Tsrv.globalVar.tableName.BPMN_LIB;
    const gpd = new ts.T_getPartDataArg();
    gpd.setFunName(tableName).setLang(that.$i18n.locale || 'en-US');
    gpd.setPage(1, 99999).setDbType(dbType);
    gpd.setFilter({
      id: {
        $in: [id]
      }
    });
    return Tsrv.getData<any, ifs.I_getPartDataArg>(gpd);
  }
}
interface I_cmd extends T_cmd {}
export { I_cmd, T_cmd };
